package com.wc.算法提高课.A第一章_动态规划.单调队列优化DP.绿色通道;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/13 23:32
 * @description https://www.acwing.com/problem/content/1092/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 50010, INF = 0x3f3f3f3f;
    // f[i] 表示第i题写的最小值, f[i], i写了, 是不是i - mid ~ i - 1都可以不写, 但是i - mid - 1必须写
    static int[] f = new int[N];
    static int[] q = new int[N];
    static int[] w = new int[N];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) w[i] = sc.nextInt();
        int l = 0, r = n;
        while (l < r) {
            int mid = l + r >> 1;
            if (check(mid)) r = mid;
            else l = mid + 1;
        }
        out.println(l);
        out.flush();
    }

    static boolean check(int mid) {
        int hh = 1, tt = 1;
        for (int i = 1; i <= n; i++) {
            if (i - mid - 1> q[hh]) hh++;
            f[i] = w[i] + f[q[hh]];
            while (hh <= tt && f[i] <= f[q[tt]]) tt--;
            q[++tt] = i;
        }
        int res = INF;
        for (int i = n - mid; i <= n; i++) res = Math.min(res, f[i]);
        return res <= m;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}